<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\controller\v1;

use app\api\model\DrivingLicense as DrivingLicenseModel;
use app\api\validate\LicenseValidate;
use app\api\validate\ParameterMustBePositiveInteger;
use app\lib\exception\SuccessMessage;
use think\Request;

class DrivingLicense extends BaseController
{
    /**
     * @desc 检查用户权限
     */
    protected $beforeActionList = [
        'checkUserScope' => ['only' => 'getlist,getdetail,insertlicense,updatelicense,deletelicense'], // 方法名必须全部小写，逗号中间不能有空格！！！
    ];

    /**
     * @Desc 获取行驶证列表
     */
    public function getList()
    {
        $license_number = Request::instance()->get('license_number');
        return DrivingLicenseModel::getList($license_number);
    }

    /**
     * @Desc 获取行驶证详情
     *
     * @param $id
     *
     * @return array
     */
    public function getDetail($id)
    {
        (new ParameterMustBePositiveInteger())->scene('id')->goCheck();
        return DrivingLicenseModel::getDetail($id);
    }

    /**
     * @Desc 添加行驶证信息
     * @return array
     */
    public function insertLicense()
    {
        (new LicenseValidate())->goCheck();
        $param = Request::instance()->post();
        return DrivingLicenseModel::insertLicense($param);
    }

    /**
     * @Desc 更新行驶证信息
     * @return SuccessMessage
     */
    public function updateLicense()
    {
        (new LicenseValidate())->goCheck();
        $param = Request::instance()->param();
        return DrivingLicenseModel::updateLicense($param);
    }

    /**
     * @Desc 删除行驶证信息
     *
     * @param $id
     *
     * @return SuccessMessage
     */
    public function deleteLicense($id)
    {
        (new ParameterMustBePositiveInteger())->scene('id')->goCheck();
        return DrivingLicenseModel::deleteLicense($id);
    }
}